/**
 * 一个类只有一个实例
 * 
 */


let Singleton = function(name){
    this.name = name
    this.instance = null
}

Singleton.prototype.getName = function(){
    console.log(this.name)
}

Singleton.getInstance = function(name){
    //确保该类只有一个实例
    if(!this.instance){
        this.instance = new Singleton(name)
    }
    return this.instance
}


let a = Singleton.getInstance("aa")
let b = Singleton.getInstance("bb")

a.getName()
b.getName()

console.log(a===b)